In [2]:
import numpy as np
In [4]:
ones_arr = np.ones((5,5))
In [6]:
ones_arr
Out[6]:
array([[1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1.]])
In [8]:
ones_arr = np.ones((5,5),dtype=int)
In [10]:
ones_arr
Out[10]:
array([[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1]])
In [12]:
zeros_arr = np.zeros((3,3),dtype=int)
In [14]:
zeros_arr
Out[14]:
array([[0, 0, 0],
[0, 0, 0],
[0, 0, 0]])
In [16]:
ones_arr
Out[16]:
array([[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1]])
In [18]:
ones_arr * 255
Out[18]:
array([[255, 255, 255, 255, 255],
[255, 255, 255, 255, 255],
[255, 255, 255, 255, 255],
[255, 255, 255, 255, 255],
[255, 255, 255, 255, 255]])
In [20]:
zeros_arr
Out[20]:
array([[0, 0, 0],
[0, 0, 0],
[0, 0, 0]])
In [22]:
ones_arr
Out[22]:
array([[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1]])
In [24]:
import matplotlib.pyplot as plt
In [26]:
%matplotlib inline
In [28]:
from PIL import Image
In [30]:
car_img = Image.open(r"C:\Users\arnav\OneDrive\Desktop\18015-MC20BluInfinito-scaled-e1707920217641.jpg")
In [36]:
car_img
Out[36]:
In [38]:
type(car_img)
Out[38]:
PIL.JpegImagePlugin.JpegImageFile
In [40]:
car_arr = np.asarray(car_img)
In [42]:
car_arr
Out[42]:
array([[[112, 104, 67],
[111, 103, 66],
[110, 102, 65],
...,
[118, 100, 60],
[117, 99, 61],
[116, 98, 60]],
[[117, 110, 68],
[117, 110, 68],
[116, 109, 67],
...,
[118, 100, 60],
[117, 99, 61],
[117, 99, 61]],
[[126, 118, 69],
[126, 118, 69],
[127, 119, 70],
...,
[115, 100, 59],
[115, 100, 61],
[115, 100, 61]],
...,
[[188, 174, 147],
[187, 173, 146],
[187, 173, 146],
...,
[191, 179, 155],
[194, 182, 158],
[195, 183, 159]],
[[187, 173, 144],
[187, 173, 144],
[186, 172, 143],
...,
[193, 181, 157],
[195, 183, 159],
[196, 184, 160]],
[[187, 173, 144],
[186, 172, 143],
[185, 171, 142],
...,
[195, 183, 159],
[196, 184, 160],
[197, 185, 161]]], dtype=uint8)
In [44]:
type(car_arr)
Out[44]:
numpy.ndarray
In [46]:
car_arr.shape
Out[46]:
(1080, 1920, 3)
In [50]:
plt.imshow(car_arr)
Out[50]:
<matplotlib.image.AxesImage at 0x1a4bada5510>
In [52]:
car_red = car_arr.copy()
In [54]:
car_red
Out[54]:
array([[[112, 104, 67],
[111, 103, 66],
[110, 102, 65],
...,
[118, 100, 60],
[117, 99, 61],
[116, 98, 60]],
[[117, 110, 68],
[117, 110, 68],
[116, 109, 67],
...,
[118, 100, 60],
[117, 99, 61],
[117, 99, 61]],
[[126, 118, 69],
[126, 118, 69],
[127, 119, 70],
...,
[115, 100, 59],
[115, 100, 61],
[115, 100, 61]],
...,
[[188, 174, 147],
[187, 173, 146],
[187, 173, 146],
...,
[191, 179, 155],
[194, 182, 158],
[195, 183, 159]],
[[187, 173, 144],
[187, 173, 144],
[186, 172, 143],
...,
[193, 181, 157],
[195, 183, 159],
[196, 184, 160]],
[[187, 173, 144],
[186, 172, 143],
[185, 171, 142],
...,
[195, 183, 159],
[196, 184, 160],
[197, 185, 161]]], dtype=uint8)
In [58]:
car_arr == car_red
Out[58]:
array([[[ True, True, True],
[ True, True, True],
[ True, True, True],
...,
[ True, True, True],
[ True, True, True],
[ True, True, True]],
[[ True, True, True],
[ True, True, True],
[ True, True, True],
...,
[ True, True, True],
[ True, True, True],
[ True, True, True]],
[[ True, True, True],
[ True, True, True],
[ True, True, True],
...,
[ True, True, True],
[ True, True, True],
[ True, True, True]],
...,
[[ True, True, True],
[ True, True, True],
[ True, True, True],
...,
[ True, True, True],
[ True, True, True],
[ True, True, True]],
[[ True, True, True],
[ True, True, True],
[ True, True, True],
...,
[ True, True, True],
[ True, True, True],
[ True, True, True]],
[[ True, True, True],
[ True, True, True],
[ True, True, True],
...,
[ True, True, True],
[ True, True, True],
[ True, True, True]]])
In [60]:
plt.imshow(car_red)
Out[60]:
<matplotlib.image.AxesImage at 0x1a4bad36350>
In [62]:
car_red.shape
Out[62]:
(1080, 1920, 3)
In [64]:
plt.imshow(car_red[:,:,0])
Out[64]:
<matplotlib.image.AxesImage at 0x1a4bb255d10>
In [66]:
car_red[:,:,0]
Out[66]:
array([[112, 111, 110, ..., 118, 117, 116],
[117, 117, 116, ..., 118, 117, 117],
[126, 126, 127, ..., 115, 115, 115],
...,
[188, 187, 187, ..., 191, 194, 195],
[187, 187, 186, ..., 193, 195, 196],
[187, 186, 185, ..., 195, 196, 197]], dtype=uint8)
In [68]:
plt.imshow(car_red[:,:,0], cmap='gray')
Out[68]:
<matplotlib.image.AxesImage at 0x1a4bb1882d0>
In [70]:
plt.imshow(car_red[:,:,0], cmap='Blues')
Out[70]:
<matplotlib.image.AxesImage at 0x1a4bb2fe350>
In [72]:
plt.imshow(car_red[:,:,0], cmap='Reds')
Out[72]:
<matplotlib.image.AxesImage at 0x1a4bb53edd0>
In [74]:
plt.imshow(car_red[:,:,0], cmap='PuBu')
Out[74]:
<matplotlib.image.AxesImage at 0x1a4bb544850>
In [80]:
plt.imshow(car_red[:,:,0], cmap='GnBu')
Out[80]:
<matplotlib.image.AxesImage at 0x1a4c49f24d0>
In [84]:
plt.imshow(car_red[:,:,1], cmap='Greys')
Out[84]:
<matplotlib.image.AxesImage at 0x1a4c4a7ed10>
In [88]:
plt.imshow(car_red[:,:,1], cmap='gray')
Out[88]:
<matplotlib.image.AxesImage at 0x1a4c532e2d0>
In [90]:
car_red[:,:,0]
Out[90]:
array([[112, 111, 110, ..., 118, 117, 116],
[117, 117, 116, ..., 118, 117, 117],
[126, 126, 127, ..., 115, 115, 115],
...,
[188, 187, 187, ..., 191, 194, 195],
[187, 187, 186, ..., 193, 195, 196],
[187, 186, 185, ..., 195, 196, 197]], dtype=uint8)
In [92]:
car_red[:,:,1]
Out[92]:
array([[104, 103, 102, ..., 100, 99, 98],
[110, 110, 109, ..., 100, 99, 99],
[118, 118, 119, ..., 100, 100, 100],
...,
[174, 173, 173, ..., 179, 182, 183],
[173, 173, 172, ..., 181, 183, 184],
[173, 172, 171, ..., 183, 184, 185]], dtype=uint8)
In [94]:
car_red[:,:,2]
Out[94]:
array([[ 67, 66, 65, ..., 60, 61, 60],
[ 68, 68, 67, ..., 60, 61, 61],
[ 69, 69, 70, ..., 59, 61, 61],
...,
[147, 146, 146, ..., 155, 158, 159],
[144, 144, 143, ..., 157, 159, 160],
[144, 143, 142, ..., 159, 160, 161]], dtype=uint8)
In [96]:
car_red[:,:,1] = 0
In [98]:
car_red[:,:,1]
Out[98]:
array([[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0],
...,
[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0]], dtype=uint8)
In [100]:
plt.imshow(car_red)
Out[100]:
<matplotlib.image.AxesImage at 0x1a4c5803e50>
In [102]:
car_red[:,:,2]
Out[102]:
array([[ 67, 66, 65, ..., 60, 61, 60],
[ 68, 68, 67, ..., 60, 61, 61],
[ 69, 69, 70, ..., 59, 61, 61],
...,
[147, 146, 146, ..., 155, 158, 159],
[144, 144, 143, ..., 157, 159, 160],
[144, 143, 142, ..., 159, 160, 161]], dtype=uint8)
In [104]:
car_red[:,:,2] = 0
In [108]:
car_red[:,:,2]
Out[108]:
array([[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0],
...,
[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0]], dtype=uint8)
In [110]:
plt.imshow(car_arr)
Out[110]:
<matplotlib.image.AxesImage at 0x1a4c5eab2d0>
In [112]:
car_arr
Out[112]:
array([[[112, 0, 0],
[111, 0, 0],
[110, 0, 0],
...,
[118, 0, 0],
[117, 0, 0],
[116, 0, 0]],
[[117, 0, 0],
[117, 0, 0],
[116, 0, 0],
...,
[118, 0, 0],
[117, 0, 0],
[117, 0, 0]],
[[126, 0, 0],
[126, 0, 0],
[127, 0, 0],
...,
[115, 0, 0],
[115, 0, 0],
[115, 0, 0]],
...,
[[188, 0, 0],
[187, 0, 0],
[187, 0, 0],
...,
[191, 0, 0],
[194, 0, 0],
[195, 0, 0]],
[[187, 0, 0],
[187, 0, 0],
[186, 0, 0],
...,
[193, 0, 0],
[195, 0, 0],
[196, 0, 0]],
[[187, 0, 0],
[186, 0, 0],
[185, 0, 0],
...,
[195, 0, 0],
[196, 0, 0],
[197, 0, 0]]], dtype=uint8)
In [114]:
car_red
Out[114]:
array([[[112, 0, 0],
[111, 0, 0],
[110, 0, 0],
...,
[118, 0, 0],
[117, 0, 0],
[116, 0, 0]],
[[117, 0, 0],
[117, 0, 0],
[116, 0, 0],
...,
[118, 0, 0],
[117, 0, 0],
[117, 0, 0]],
[[126, 0, 0],
[126, 0, 0],
[127, 0, 0],
...,
[115, 0, 0],
[115, 0, 0],
[115, 0, 0]],
...,
[[188, 0, 0],
[187, 0, 0],
[187, 0, 0],
...,
[191, 0, 0],
[194, 0, 0],
[195, 0, 0]],
[[187, 0, 0],
[187, 0, 0],
[186, 0, 0],
...,
[193, 0, 0],
[195, 0, 0],
[196, 0, 0]],
[[187, 0, 0],
[186, 0, 0],
[185, 0, 0],
...,
[195, 0, 0],
[196, 0, 0],
[197, 0, 0]]], dtype=uint8)
In [116]:
car_img
Out[116]:
In [118]:
arr1 = np.asarray(car_img)
In [120]:
type(arr1)
Out[120]:
numpy.ndarray
In [124]:
arr1.shape
Out[124]:
(1080, 1920, 3)
In [126]:
plt.imshow(arr1)
Out[126]:
<matplotlib.image.AxesImage at 0x1a4c5f2cb90>
In [128]:
car_img1 = arr1.copy()
In [130]:
car_img1[:,:,0] = 0
In [132]:
plt.imshow(car_img1)
Out[132]:
<matplotlib.image.AxesImage at 0x1a4c72e6d10>
In [134]:
car_img1[:,:,1] = 0
In [136]:
plt.imshow(car_img1)
Out[136]:
<matplotlib.image.AxesImage at 0x1a4c7204110>
In [ ]: